using UnityEngine;

public class AlivePersonBehaviour : EntityBehaviour
{
	public Vector2 distPlayer = new Vector2(100f, 100f);

	public AlivePersonBehaviour(ZombieInHome zombie)
		: base(zombie)
	{
	}

	public override void OnUpdate()
	{
		if (!zombie.isDead && !(Player.onStage == null))
		{
			distPlayer = Player.onStage.transform.position - zombie.transform.position;
			stateAnimator = zombie.animator.GetCurrentAnimatorStateInfo(0);
			currentSpeed.x = zombie.speedMove * stateAnimator.speed * stateAnimator.speedMultiplier * Mathf.Min(0.05f, Time.deltaTime);
			currentSpeed.y = 0f;
			if (-12f < distPlayer.x && distPlayer.x < -5f && currentSpeed.x < 0f)
			{
				currentSpeed.y = Mathf.Sin(Mathf.Atan2(distPlayer.y, distPlayer.x)) * Mathf.Abs(currentSpeed.x);
			}
			zombie.transform.position += currentSpeed;
			if (distPlayer.x > 4f)
			{
				UnityEngine.Object.Destroy(zombie.gameObject);
				GameSavingPeople.scene.OnSavedPerson();
			}
		}
	}

	public override void OnDeath()
	{
		base.OnDeath();
		Object.FindObjectOfType<GameSavingPeople>().OnDeathPeople(zombie);
	}
}
